﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RayTracing
{
    class Mirror : Skin
    {
        float refactiveIndex;
        float reflectiveIndex;
        float opacity;

        public Mirror()                     // needs to be fleshed out 
        {
            this.opacity = 1;               // May need to take something like "Reflectiveness"??
        }

        public Mirror(float refactiveIndex, float reflectiveIndex, float opacity)
        {
            this.refactiveIndex = refactiveIndex;
            this.reflectiveIndex = reflectiveIndex;
            this.opacity = opacity;
        }

        #region Skin Members

        public Color color(P3 pointOnSurface, Ray r, SceneObject sceneObject)   // returns the color on the object at the point
        {

            //Color refracted;

            // gets the color of the texture at the point on the surface of the SceneObject.
            P2 textureLocation = sceneObject.geometry.toP2(pointOnSurface);
            Color textureColor = sceneObject.texture.textureAt(textureLocation);

            // (Dark Magic)
            P3 V = r.direction;
            P3 N = sceneObject.geometry.normal(pointOnSurface);
            float c1 = -P3.dot( N, V );
            P3 R1 = P3.add(V , (P3.scale(P3.scale(N,2),c1) )); 

             // Dark Magic for refracted light.

            //Note that since V, N, and Rl are vectors with x, y, and z components, 
            //the arithmetic on them is performed per-component. 
            //The refracted ray position Rr is given by

            //if(opacity < 1){
            //   refracted =  refract(1, refactiveIndex);
           
            //}
            Color reflectedRay = Main.shootRay(new Ray(pointOnSurface, R1));

            return reflectedRay;           // returns a color from the ray that hits other objects.

        }

        //public Color refract(float originalIndex, float newIndex){
        //    n1 = originalIndex;
        //    n2 = newIndex;
        //    n = n1 / n2;
        //    c2 = sqrt( 1 - n2 * (1 - c12) );

        //    Rr = (n * V) + (n * c1 - c2) * N;

        //    return refract(newIndex,originalIndex);
        //}

        #endregion
    }
}
